package com.jnu.hc.jnuhcdoccms.service;

import com.jnu.hc.jnuhcdoccms.dto.ROrderListRequestDto;
import com.jnu.hc.jnuhcdoccms.dto.ResponseObject;
import com.jnu.hc.jnuhcusercms.domain.Cidetailedreport;
import com.jnu.hc.jnuhcusercms.domain.Cireport;
import com.jnu.hc.jnuhcusercms.domain.Orders;
import com.jnu.hc.jnuhcusercms.mapper.CheckitemdetailedMapper;
import com.jnu.hc.jnuhcusercms.mapper.CidetailedreportMapper;
import com.jnu.hc.jnuhcusercms.mapper.CireportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    CidetailedreportMapper  cidetailedreportMapper;
    @Autowired
    CireportMapper cireportMapper;
    @Autowired
    private CheckitemdetailedMapper checkitemdetailedMapper;

    @Transactional
    @Override
    public ResponseObject createReportTemplate(Orders orders){
        List<Cireport> cireportList=cireportMapper.selectByOrderId(orders.getOrderId());
        if(cireportList.size()>0){
            System.out.println("已经存在模板");
            return new ResponseObject<>(200,"成功1");
        }else {
            List<Cireport> cireports=cireportMapper.selectBySmId(orders.getSmId());
            for(Cireport cireport:cireports){
                cireport.setOrderId(orders.getOrderId());
                cireportMapper.insert(cireport);
            }
            List<Cidetailedreport> cidetailedreports=checkitemdetailedMapper.selectBySmId(orders.getSmId());
            for(Cidetailedreport cd:cidetailedreports){
                cd.setOrderId(orders.getOrderId());
                cidetailedreportMapper.insertSelective(cd);
            }

            return new ResponseObject<>(200,"成功2");
        }
    }
}
